package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书....");
        System.out.println("请输入你要归还书的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = bookList.getSize();
        for(int i = 0;i<size;i++){
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
               if(!book.getLend()){
                   System.out.println("该书还未被借出...");
                   return;
               }
               book.setLend(false);
                System.out.println("归还成功...");
                return;
            }
        }
        System.out.println("很抱歉，未找到这本书...");
    }
}
